﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodMan.Infrastructure.Entities.Repository;
using GoodMan.Infrastructure.Entities.Enum;

namespace GoodMan.Infrastructure.Entities.Entity
{
    public class OrderDetail : IAccessible<T_OrderDetail, OrderDetail>, ILogicEntity<T_OrderDetail, OrderDetail>
    {
        public int Id { get; set; }
        public int OrderId { get; set; }
        public AreaCode AreaCode { get; set; }
        public int ProductId { get; set; }
        public string ProductName { get; set; }
        public int ProductType { get; set; }
        public int ProductSubType { get; set; }
        public int Num { get; set; }
        public decimal Price { get; set; }
        public int PolicyId { get; set; }
        public decimal OffPrice { get; set; }
        public string Remark { get; set; }

        public string verValue { get; set; }

        public int productRemain { get; set; }
        /// <summary>
        /// 配菜信息
        /// </summary>
        public string Catering { get; set; }

        public Order order { get; set; }

        public OrderDetail LoadOrder(T_Order order)
        {
            this.order = new Order().Set(order);
            return this;
        }

        public User user { get; set; }

        public OrderDetail LoadUser(T_User user)
        {
            this.user = new User().Set(user);
            return this;
        }

        protected override void Covariant(T_OrderDetail model)
        {
            if (model != null)
            {
                Id = model.Id;
                OrderId = model.OrderId;
                AreaCode = (AreaCode)model.AreaCode;
                Num = model.Num;
                OffPrice = model.OffPrice;
                PolicyId = model.PolicyId;
                Price = model.Price;
                ProductId = model.ProductId;
                ProductName = model.ProductName;
                ProductSubType = model.ProductSubType;
                ProductType = model.ProductType;
                Remark = model.Remark;
                Catering = model.Catering;
            }
        }

        protected override T_OrderDetail Inverter(OrderDetail model)
        {
            if (model != null)
            {
                return new T_OrderDetail()
                {
                    Id = model.Id,
                    OrderId=model.OrderId,
                    AreaCode=(int)model.AreaCode,
                    Num = model.Num,
                    OffPrice = model.OffPrice,
                    PolicyId = model.PolicyId,
                    Price = model.Price,
                    ProductId = model.ProductId,
                    ProductName = model.ProductName,
                    ProductSubType = model.ProductSubType,
                    ProductType = model.ProductType,
                    Remark = model.Remark,
                    Catering=model.Catering
                };
            }
            return null;
        }

        public OrderDetail Set(T_OrderDetail dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
